import numpy as np
import csv

def load_data(file_path):
    data = []
    with open(file_path, 'r', encoding='utf-8') as csvfile:
        reader = csv.reader(csvfile)
        next(reader)
        for row in reader:
            stars = int(row[2])
            forks = int(row[3])
            created_at = np.datetime64(row[5])
            last_commit = np.datetime64(row[6])
            active_days = (last_commit - created_at).astype('timedelta64[D]').astype(int)
            data.append([stars, forks, active_days])
    return np.array(data, dtype=float)


def calculate_statistics(data):
    means = np.round(np.mean(data, axis=0), 1)
    medians = np.round(np.median(data, axis=0), 1)
    variances = np.round(np.var(data, axis=0), 1)
    stds = np.round(np.std(data, axis=0), 1)
    return {
    'means': means,
    'medians': medians,
    'variances': variances,
    'stds': stds}


def print_results(stats):
    metrics = ['Stars', 'Forks', 'Active Days']
    for metric, mean, med, var, std in zip(metrics,
                                        stats['means'],
                                        stats['medians'],
                                        stats['variances'],
                                        stats['stds']):
        print(f"{metric}:")
        print(f" Average: {mean}")
        print(f" Median: {med}")
        print(f" Variance: {var}")
        print(f" Standard Deviation: {std}")


repo_data = load_data('china-repos.csv')
stats = calculate_statistics(repo_data)
print_results(stats)